package com.briup.ch13;

import java.lang.reflect.Field;

/**
 * @author yuxi
 * @version 1.0
 * @date 2025/10/21
 * @Description:
 */
public class Test06 {
    public static void main(String[] args) throws NoSuchFieldException {
        Class clazz = Student.class;
        //获得所有public的字段
        Field[] fields = clazz.getFields();
        for (Field field : fields) {
            System.out.println(field.getName());
        }
        System.out.println("=====           ");
        //获得所有字段，包括private和protected
        Field[] declaredFields = clazz.getDeclaredFields();
        for (Field field : declaredFields) {
            System.out.println(field.getName());
        }
        //获得所有public的单个字段
        Field nameField = clazz.getField("id");
        System.out.println(nameField.getName());
        //获得所有public的单个字段，包括private和protected
        Field ageField = clazz.getDeclaredField("age");
        System.out.println(ageField.getName());
        //获得所有public的静态字段
        System.out.println(clazz.getField("count").getName());

    }
}
